import * as XLSX from 'xlsx'
// import { useState } from 'react'

const useFile = (fileRef) => {
    // const [ prolist, setProlist ] = useState([])

    const clickHandle = () => {
        fileRef.current.click()
    }

    const fileChangeFn = () => {
        const file = fileRef.current.files[0]
        const reader = new FileReader()
        reader.readAsBinaryString(file)
        return new Promise( resolve => {
            reader.onload = function () {
                const workbook = XLSX.read(this.result, { type: 'binary' });
                const t = workbook.Sheets['工作表1']
                const r = XLSX.utils.sheet_to_json(t)
                resolve(r)
            }
        })
    }
    return {
        clickHandle,
        fileChangeFn
    }
}

export default useFile